timer object

This method will pause the timer.

bool pause()

Parameters:
None.

Return value:
true on success, false on failure.

Remarks:
This method makes the timer stop completely and remain at its current position until either the resume or the restart method is called on it. This is useful when you wish to create a pause feature in your game for instance. Note that it will fail if the timer is already paused.

Example:
// Play ding every 250MS using two buffers to avoid cutting the sound off as quickly, and let user press escape to quit and p to pause/unpause timer.

void main()
{
sound ding1;
sound ding2;
show_game_window("Timer Test");

ding1.load("C:\\Windows\\media\\ding.wav");
ding2.load("C:\\Windows\\media\\ding.wav");
if(ding1.active==false)
{
alert("Error", "The sound could not be loaded.");
exit();
}
if(ding2.active==false)
{
alert("Error", "The sound could not be loaded.");
exit();
}

// We pan the two buffers a little bit so that they can be distinguished.
ding1.pan=-20;
ding2.pan=20;

int current_buffer=1;
bool paused=false;

ding1.play();

timer counter;

while(true)
{
if(key_pressed(KEY_ESCAPE))
{
exit();
}
if(key_pressed(KEY_P))
{
if(paused==true)
{
paused=false;
counter.resume();
}
else
{
counter.pause();
paused=true;
}
}
if(counter.elapsed>=250)
{
counter.restart();
if(current_buffer==1)
{
current_buffer=2;
if(ding2.playing==true)
{
ding2.stop();
}
ding2.play();
}
else
{
current_buffer=1;
if(ding1.playing==true)
{
ding1.stop();
}
ding1.play();
}
}
wait(5);
}
}